package com.wanshu.controller;


import com.alibaba.fastjson.JSON;
import com.wanshu.util.SearchHistoryUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@CrossOrigin("http://localhost:8080")
@RequestMapping("/search")
public class SearchController {

    private final SearchHistoryUtil searchHistoryUtil = new SearchHistoryUtil();
    @RequestMapping("/getSearchHistory")
    public String getSearchHistory() throws IOException {
        List<String> searchCache = searchHistoryUtil.getSearchCache();
        return JSON.toJSONString(searchCache);
    }

    @RequestMapping("/addSearchHistory")
    public void addSearchHistory(String message){
        searchHistoryUtil.setSearchCache(message);
    }
}
